//---------------------------------------------------------------------------
// MyConMan Class
// Author : Alex Woo-Hyun Kim at www.webrobot.org
// Email : woorung@webrobot.org,webrobot@hotmail.com,woorung@empal.com
// Date : Apr. 17, 2002
//
// This class manage connection pool to MySQL by means of circular queue.
//---------------------------------------------------------------------------
#ifndef CMyConManH
#define CMyConManH
//---------------------------------------------------------------------------
#include <mysql.h>
//--------------------------------------------------------------------------
struct TMyConPool {
	bool bUse;
	MYSQL *pMyCon;
};
//---------------------------------------------------------------------------
class CMyConMan {
private :
	// related to reference count
	static unsigned int g_iRefCount;

	// related to connection pool
	static unsigned int g_iMaxCon;
	static unsigned int g_iCurPos;
        static TMyConPool *g_pMyConPool; // it will be circular queue

	// related to configuration file for mysql
        char *m_pszHost;
        char *m_pszPort;
        char *m_pszSocket;
        char *m_pszUser;
        char *m_pszPasswd;
        char *m_pszDB;
        char *m_pszFlags;

	bool GetRealConnections();
	void FreeRealConnections();
	bool GetConfigFile(char *pszConfigFileName);
	void SetConfigVariable(char *pszName,char *pszValue,char **pszConfigVariables);

protected :
	void FreeConnection(MYSQL *pMyCon);

public :
	CMyConMan(char *pszConfigFileName);
	~CMyConMan();
	MYSQL *GetConnection();
	
#ifdef DEBUG
	void Debug(char *str);
	void Debugln(char *str);
	void Debug(int i);
	void Debugln(int i);
#endif
};
//---------------------------------------------------------------------------
#endif
